<?php
require_once(dirname(dirname(__FILE__)) . '/app.php');
if ($_POST||$_GET) {
	if (!$_POST){
		$_POST = $_GET;
  }
  
  if ($_POST['type']=='feedback'){
			if (!$_POST['u'] || !$_POST['p'] || !$_POST['m']|| !$_POST['c']) {
				die("-1");
			}
			
			global $INI;
			$user = $INI['sms']['smsbao_user']; 		//短信平台帐号
			$pass = md5($INI['sms']['smsbao_pass']);			//短信平台密码
			if ($_POST['u'] != $user || $_POST['p'] != $pass){
				die("40");
			}
			
			$table = new Table('feedback', $_POST);
			$table->city_id = "0";
			$table->create_time = time();
			$table->category = 'sms';
			$table->title = "";
			$table->content = htmlspecialchars($table->c);
			$table->contact = htmlspecialchars($table->m);
			$table->user_id = "0";

			$mobileuser = DB::GetTableRow ('toolsbind',array( 
		      'enable' => 'Y',
		      'tools' => $_POST['m'],
			));
			
			if ($mobileuser){
				$table->user_id = $mobileuser['user_id'];
			}else{
				$mobileuser = DB::GetTableRow('user', array(
						'mobile' => $_POST['m'],
				));
				if ($mobileuser){
					$table->user_id = $mobileuser['id'];
				}
			}

			$table->Insert(array(
				'city_id', 'title', 'contact', 'content', 'create_time',
				'category','user_id'
			));
			die("0");
  }else{
  		die("-1");
  }
}else{
	die("-1");
}